# class Course:  # 课程类
#     def __init__(self, name, c_digit, number, num):  # 定义属性：课程名称,课程编号,最大选课人数,已选人数
#         self.name = name
#         self.digit = c_digit
#         self.number = number
#         self.num = num
#
#     def show_courses(self):  # 展示课程信息
#         return f"课程名称是{self.name},课程编号是{self.digit},课程容量是{self.number},已选人数{self.num}"
#
#     @staticmethod
#     def course_digit(digit):  # 静态方法：验证课程编号是否合法
#         if len(digit) == 5 and digit.startswith("C") and digit.isalnum():  # 以 "C" 开头的 5 位字母和数字组合
#             print("课程编号合法")
#         else:
#             print("课程编号不合法")
#
# class Student:  # 学生类
#     def __init__(self, name, s_digit):  # 定义属性：学生名称,学生学号
#         self.name = name
#         self.digit = s_digit
#         self.course_list = []  # 已选课程列表存课程对象
#
#     def show_students(self):  # 展示学生信息
#         get_course = []  # 存放名字的列表
#         if self.course_list:
#             for course in self.course_list:
#                 get_course.append(course.name)
#         else:
#             get_course.append("无")
#         return f"学生姓名是{self.name},学号是{self.digit},已选课程{get_course}"
#
#     @staticmethod
#     def student_digit(digit):  # 静态方法：验证学号是否合法
#         if len(digit) == 8 and digit.isdigit():
#             print("学号合法")
#         else:
#             print("学号不合法")
#
# class CourseManager:
#     def __init__(self):
#         self.courses = []  # 课程列表
#         self.students = []  # 学生列表
#
#     def add_course(self, course):  # 添加课程
#         if course not in self.courses:
#             self.courses.append(course)
#             return f"课程{course.name}已添加"
#         else:
#             return f"课程{course.name}已存在"
#
#     def delete_course(self, course):  # 删除课程
#         if course in self.courses:
#             self.courses.remove(course)
#             return f"课程{course.name}已删除"
#         else:
#             return f"课程{course.name}不存在"
#
#     def show_course(self):  # 查看所有课程
#         if self.courses:
#             for course in self.courses:
#                 print(f"{course.show_courses()}")
#         else:
#             print("课程为空")
#
#     def add_student(self, student):  # 添加学生
#         if student not in self.students:
#             self.students.append(student)
#             return f"学生{student.name}已添加"
#         else:
#             return f"学生{student.name}已存在"
#
#     def delete_student(self, student):  # 删除学生
#         if student in self.students:
#             self.students.remove(student)
#             return f"学生{student.name}已删除"
#         else:
#             return f"学生{student.name}不存在"
#
#     def show_student(self):  # 查看所有学生
#         if self.students:
#             for student in self.students:
#                 print(f"{student.show_students()}")
#         else:
#             print("学生为空")
#
#     def select_course(self, student, course):  # 选课
#         if student in self.students and course in self.courses:  # 学生和课程都存在
#             if course.num <= course.number:  # 已选课程人数<=最大课程人数
#                 if course not in student.course_list:  # 课程不在学生已选课程列表
#                     student.course_list.append(course)
#                     print(f"{student.name}成功选择{course.name}课程")
#                 else:
#                     print(f"{student.name}选择失败{course.name}课程")
#             else:
#                 print(f"{course.number}课程已选满")  # 最大课程人数已满
#             course.num += 1
#         else:
#             print(f"{student.name}或者{course.name}不存在")
#
#     def drop_course(self, student, course):  # 退课
#         if student in self.students and course in self.courses:  # 学生和课程都存在
#             if course in student.course_list:  # 课程在学生已选课程列表
#                 student.course_list.remove(course)
#                 print(f"{student.name}成功退{course.name}课程")
#             else:
#                 print(f"{student.name}没选过{course.name}课程")
#             course.num -= 1
#         else:
#             print(f"{student.name}或者{course.name}不存在")
#
# m = CourseManager()
# # 获取课程对象
# c1 = Course("python", "C0001", 3, 1)
# c2 = Course("Java", "C0002", 4, 1)
# # 获取学生对象
# s1 = Student("Tom", "10000001")
# s2 = Student("Jay", "10000002")
# m.add_course(c1)
# m.add_course(c2)
# m.add_student(s1)
# m.add_student(s2)
# # 判断合法
# Course.course_digit("S3453")
# Student.student_digit("100000011")
# # 选课
# m.select_course(s1, c1)
# m.select_course(s2, c2)
# # 退课
# m.drop_course(s1, c1)
# # 展示课程和学生
# m.show_course()
# m.show_student()
